#include <iostream>
#include <string>

#include "Log.hpp"
#include "Message.hpp"
#include "net.hpp"

using namespace LogArea;

void OnMessage(const MyRpc::BaseConnection::con_ptr& conn,MyRpc::BaseMessage::msg_ptr& msg)
{
    std::string body = msg->Serialize();
    LogArea::LOG(LogLevel::DEBUG)<<"Server get message body: "<<body;
    auto rpc_rsp = MyRpc::MessageFactory::create<MyRpc::RPcResponse>();
    rpc_rsp->SetId("11111");
    rpc_rsp->SetMtype(MyRpc::MType::RSP_RPC);
    rpc_rsp->SetRcode(MyRpc::RCode::RCODE_OK);
    rpc_rsp->SetResult(33);
    conn->Send(rpc_rsp);
}

int main()
{
    auto server = MyRpc::MuduoServerFactory::create(9092);
    server->SetMsgCb(OnMessage);
    server->Start();
    return 0;
}